package com.wwy.user.utils;

import org.springframework.security.crypto.bcrypt.BCrypt;

/**
 * @author 王伟羽
 * @program: almighty
 * @description: 密码加密工具
 * @create: 2025/01/08
 */

public class PasswordBCrypt {
    public static String hashPasswordBCrypt(String password) {
        // 生成哈希密码，默认成本因子为 10
        return BCrypt.hashpw(password, BCrypt.gensalt());
    }

    public static boolean checkPassword(String password, String hashedPassword) {
        // 检查密码是否匹配
        return BCrypt.checkpw(password, hashedPassword);
    }

    public static void main(String[] args) {
        String password = "kunkun123456";
        String hashedPassword = hashPasswordBCrypt(password);
        System.out.println("Hashed Password: " + hashedPassword);
        boolean isMatch = checkPassword(password, hashedPassword);
        System.out.println("Password Match: " + isMatch);
    }
}
